package com.yoomiito.app.ui.yijiayou

import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.oil.*

class TuanYouDetailPresenter(appConfig: AppConfig) : BaseActPresenter<GasStationDetailActivity>(appConfig) {

    fun dataHandle(data: OilStationDetailData): OilStationInfo {
        val types = mutableListOf(
                OilType(1, "汽油", mutableListOf(), false),
                OilType(2, "柴油", mutableListOf(), false),
                OilType(3, "天然气", mutableListOf(),false)
        )
        data.detail.forEach {
            val gunNo = mutableListOf<OilGunNum>()
            it.gunNos.forEach { gun ->
                gunNo.add(OilGunNum(gun.gunNo, false))
            }
            // oilType 1 汽油 2 柴油 3 天然气
            if (it.oilType in 1..3) {
                if (it.oilNo == data.selectOilNum) {//判断 哪种类型的油是在列表选中
                    types[it.oilType - 1].select = true
                }
                types[it.oilType - 1] //将各种油的油号进行归类，并将列表中选中的油号标识为选中，其他为未选中
                        .oilNum
                        .add(
                                OilNum(it.oilName,
                                        it.oilNo,
                                        it.oilType,
                                        it.priceYfq,
                                        it.priceGun,
                                        it.oilNo == data.selectOilNum,
                                        it.productId,
                                        gunNo
                                )
                        )
            }
        }
        types.forEach {//在列表选中未选中的油类型 默认选中第一个油号
            if (!it.select&&it.oilNum.isNotEmpty()){
                it.oilNum[0].select = true
            }
        }
        return OilStationInfo(data.gasId,
                data.gasName,
                data.gasType,
                "${data.province?:""}${data.city?:"" }${data.county?:""}${data.gasAddress}",
                data.type,
                data.lng,
                data.lat,
                data.logo,
                data.distance.toDouble(),
                types
        )
    }
}